package main

import (
	"fmt"
	"net/http"
	"os"
	"path/filepath"

	"github.com/gin-gonic/gin"
)

func main() {
	r := gin.Default()

	// 加载单个template文件
	// r.LoadHTMLFiles("templates/index.tmpl")
	// 加载多个template文件
	// r.LoadHTMLGlob("templates/*")
	r.LoadHTMLGlob("templates/**")

	dir, _ := filepath.Abs(filepath.Dir(os.Args[0]))
	fmt.Println("dir", dir)
	// dir /var/folders/5k/sr5_svmd67364yzspxgm2m9c0000gn/T/go-build3353565413/b001/exe
	// dir /private/var/folders/5k/sr5_svmd67364yzspxgm2m9c0000gn/T/GoLand

	r.GET("/html", func(c *gin.Context) {
		c.HTML(http.StatusOK, "index.tmpl", gin.H{
			"title": "慕课网",
		})
	})

	r.GET("/goods", func(c *gin.Context) {
		c.HTML(http.StatusOK, "goods.tmpl", gin.H{
			"title": "商品呀",
		})
	})

	r.GET("/users", func(c *gin.Context) {
		c.HTML(http.StatusOK, "users.tmpl", gin.H{
			"title": "用户列表",
		})
	})

	_ = r.Run()
}
